import com.ridgesoft.intellibrain.IntelliBrain;
import com.ridgesoft.robotics.RangeFinder;
import com.ridgesoft.robotics.sensors.ParallaxPing;

public class Killer implements Runnable{
	private static int KILL_PORT = 3;

	private int _killData;
	
	private ParallaxPing _killSwitch;

	
	private static final Killer instance = new Killer();
	
	public Killer()
	{		
	}
	public void init()
	{
		_killSwitch = new ParallaxPing(IntelliBrain.getDigitalIO(KILL_PORT));
	}
	public int getKillData()
	{
		return _killData;
	}
	public void UpdateSensor()
	{
		_killSwitch.ping();
			
		try
		{
			Thread.sleep(100);
		}
		catch(InterruptedException e)
		{
			e.printStackTrace();
		}
		_killData = (int)_killSwitch.getEchoDelay();			
	}
	
	public boolean checkKillStatus(){
		int kd = getKillData();
		
		if((kd < 1200) && (kd > 1000)){
			return true;
		} else {
			return false;
		}
	}
	
	@Override
	public void run() 
	{
		init();
		while(true)
		{
			Thread.yield();
			UpdateSensor();	
		}
	}
	  public static Killer getInstance() {
	        return instance;
	    }

	
}
